<template>
  <view class="container screen-width">
    <view class="top_bar">
      <view class="logo">
        <image src="../../static/tabBar/logo.png"></image>
      </view>
      <view class="search_bar">
        <view class="location" @tap="selectLocation">
          {{ city }}
          <!-- 字体图标开始 -->
          <svg
            t="1615946699743"
            class="icon"
            viewBox="0 0 1024 1024"
            version="1.1"
            xmlns="http://www.w3.org/2000/svg"
            p-id="2034"
            width="200"
            height="200"
          >
            <path
              d="M230.56060922 329.85011292c-32.74599016 0-53.69192362 43.72842908-28.60286236 68.81893873L483.84324265 680.57554913c16.17275477 16.16406441 40.21607637 16.16406441 56.38158917 0L822.12263893 398.67701781c24.45249259-24.45973456 5.38367629-68.81893873-28.19441556-68.81893873l-563.36833834-0.00796616z"
              fill="#ffffff"
              p-id="2035"
            ></path>
          </svg>
          <!-- 字体图标结束 -->
        </view>
        <view class="search_bar_top">
          <text
            :class="currentIndex == index ? 'active' : ''"
            v-for="(item, index) in titleItem"
            :key="index"
            @tap="currentItem(index, item.itemValue)"
            >{{ item.itemText }}</text
          >
        </view>
        <view class="search_barimage">
          <input
            type="text"
            @blur="getHistoryList(currentIndex, 'blur')"
            @focus="getHistoryList(currentIndex, 'focus')"
            v-if="titleItem[currentIndex] && titleItem[currentIndex].itemText"
            :placeholder="`输入你要查询的` + titleItem[currentIndex].itemText.split('查')[1]"
            v-model="keyWord"
          />
          <image src="../../static/tabBar/search_icon.png" @tap="handleBtn"></image>
          <!-- 查企业列表-->
          <view class="dataBox" v-if="currentIndex == 0">
            <view class="list-content">
              <view v-show="!showHistory && companyNameItem.length > 0">
                <view
                  class="policy_item"
                  hover-class="none"
                  @tap="goToCompanyList(item.companyId, item.companyName)"
                  v-for="(item, index) in companyNameItem"
                  :key="index"
                >
                  <p v-html="item.companyName"></p>
                </view>
              </view>
              <!-- 历史记录 -->
              <view v-show="showHistory">
                <view
                  class="policy_item"
                  hover-class="none"
                  @tap="goToCompanyList(item.companyId, item.companyName)"
                  v-for="(item, index) in searchList"
                  :key="index"
                >
                  <p v-html="item.companyName"></p>
                </view>
              </view>
              <view v-if="searchList.length > 0 && showHistory" class="flex items-middle flex-end search-history-btn">
                <view @tap="toMore">更多历史</view>
                <view @tap="toClear">清空历史</view>
              </view>
            </view>
          </view>
          <!-- 查政策列表 -->
          <view class="dataBox" v-if="policy.length > 0 && keyWord != '' && currentIndex == 1">
            <view class="list-content">
              <view class="policy_item" @tap="gotoPolicy(item.policyId, item.title)" v-for="(item, index) in policy" :key="index">
                <p v-html="item.title"></p>
              </view>
            </view>
          </view>
          <!-- 查项目列表 -->
          <view class="dataBox" v-if="projectList.length > 0 && keyWord != '' && currentIndex == 2">
            <view class="list-content">
              <view class="policy_item" @tap="gotoProject(item.projectName)" v-for="(item, index) in projectList" :key="index">
                <p v-html="item.projectName"></p>
              </view>
            </view>
          </view>
        </view>
        <view class="search_bar_keyword">
          <view class="title">热门搜索:</view>
          <view class="keyWord">
            <span v-for="(item, index) in keyItem" :key="index" @tap="hanlderItem(item.sourceId, item.name)">{{ item.name }}</span>
          </view>
        </view>
      </view>
    </view>
    <!-- 滚动时固定 -->
    <!-- 搜索框顶固 -->
    <div class="fixation_box screen-width" v-show="isfixed">
      <div class="fixation_search">
        <view class="search_bar">
          <input
            type="text"
            v-if="titleItem[currentIndex] && titleItem[currentIndex].itemText"
            :placeholder="`输入你要查询的` + titleItem[currentIndex].itemText.split('查')[1]"
            v-model="keyWord"
          />
          <image src="../../static/proty/search_icon.png" mode="" @tap="handleBtn" />
        </view>
      </div>
      <div class="fixation_title">
        <view
          :class="contentTitleItem == index ? 'active' : ''"
          class="title_item"
          @tap="hanlderEvent(index)"
          v-for="(item, index) in titleContent"
          :key="index"
          >{{ item }}</view
        >
      </div>
      <view class="sreach_content">
        <!-- 查企业 -->
        <ul v-if="companyNameItem.length > 0 && keyWord != '' && currentIndex == 0 && isfixed">
          <li @tap="goToCompanyList(item.companyId, item.companyName)" class="list" v-for="(item, index) in companyNameItem" :key="index">
            <p v-html="item.companyName"></p>
          </li>
        </ul>
        <!-- 查政策 -->
        <ul v-if="policy.length > 0 && keyWord != '' && currentIndex == 1 && isfixed">
          <navigator class="list" hover-class="none" @tap="gotoPolicy(item.policyId, item.title)" v-for="(item, index) in policy" :key="index"
            ><p v-html="item.title"></p
          ></navigator>
        </ul>
        <!-- 查项目 -->
        <ul v-if="projectList.length > 0 && keyWord != '' && currentIndex == 2 && isfixed">
          <navigator hover-class="none" @tap="gotoProject(item.projectName)" v-for="(item, index) in projectList" :key="index">
            <p v-html="item.projectName"></p>
          </navigator>
        </ul>
      </view>
    </div>
    <!-- 图标 -->
    <view class="icon-list flex flex-wrap space-around">
      <view @tap="toPage(false, '/pages/policy/policySubscription')" class="item flex flex-col flex-center items-middle">
        <view class="dot flex flex-center items-middle">
          <img src="../../static/home/01.png" />
        </view>
        <view>政策订阅</view>
      </view>
      <view @tap="toPage(false, '/pages/compare/index')" class="item flex flex-col flex-center items-middle">
        <view class="dot flex flex-center items-middle">
          <img src="../../static/home/02.png" />
        </view>
        <view class="text">企业对比</view>
      </view>
      <view @tap="toPage(false, '/pages/companyWeb/list')" class="item flex flex-col flex-center items-middle">
        <view class="dot flex flex-center items-middle">
          <img src="../../static/home/03.png" />
        </view>
        <view class="text">企业名片</view>
      </view>
      <!-- <view @tap="toPath(false,'/pages/result/index')" class="item flex flex-col flex-center items-middle">
        <view class="dot flex flex-center items-middle">
          <img src="../../static/home/04.png" />
        </view>
        <view class="text">科技成果</view>
      </view> -->
      <view @tap="toPage(false, '/pages/business/search/Index')" class="item flex flex-col flex-center items-middle">
        <view class="dot flex flex-center items-middle">
          <img src="../../static/home/08.png" />
        </view>
        <view class="text">商业计划</view>
      </view>
      <view @tap="toPage(false, '/pages/declare/search')" class="item flex flex-col flex-center items-middle">
        <view class="dot flex flex-center items-middle">
          <img src="../../static/home/05.png" />
        </view>
        <view class="text">企业测评</view>
      </view>
      <view @tap="toPage(true, '/pages/patent/search/Index')" class="item flex flex-col flex-center items-middle">
        <view class="dot flex flex-center items-middle">
          <img src="../../static/home/07.png" />
        </view>
        <view class="text">专利监管</view>
      </view>
      <view @tap="toPage(true,'/pages/person/CardList')" class="item flex flex-col flex-center items-middle">
        <view class="dot flex flex-center items-middle">
          <img src="../../static/home/06.png">
        </view>
        <view class="text">个人名片</view>
      </view>
      <view @tap="toPage(false,'/pages/product/productList/Index')" class="item flex flex-col flex-center items-middle">
        <view class="dot flex flex-center items-middle">
          <img src="../../static/home/10.png">
        </view>
        <view class="text">政策商城</view>
      </view>
      <view @tap="toPage(false,'/pages/activity/createList/Index')" class="item flex flex-col flex-center items-middle">
        <view class="dot flex flex-center items-middle">
          <img src="../../static/home/09.png">
        </view>
        <view class="text">创建活动</view>
      </view>
    </view>
    <!-- 首页列表数据 -->
    <view class="content">
      <view class="title_text">
        <span v-for="(item, index) in titleContent" :class="contentTitleItem === index ? 'active' : ''" :key="index" @tap="hanlderEvent(index)">{{
          item
        }}</span>
      </view>
      <!-- 资讯 -->
      <navigator
        class="content_text"
        :url="`/pages/policy/newsDetail?id=${item.id}`"
        hover-class="className"
        v-show="contentTitleItem == 0"
        v-for="(item, index) in newsList"
        :key="index"
      >
        <view class="title">
          {{ item.title }}
        </view>
        <view class="name_data">
          <!-- <text class="departmentName">{{ item.label }}</text> -->
          <text class="endTime" v-if="item && item.createTime">{{ item.createTime }}</text>
        </view>
      </navigator>

      <!-- 通知 -->
      <navigator
        class="content_text"
        :url="`/pages/policy/policyDetails?id=${item.policyId}&inform=通知`"
        hover-class="className"
        v-show="contentTitleItem == 1"
        v-for="(item, k) in getNotifyList"
        :key="k + item.policyId"
      >
        <view class="title">
          {{ item.title }}
        </view>
        <view class="name_data">
          <text class="departmentName">{{ item.label }}</text>
          <text class="endTime">{{ item.date }}</text>
        </view>
      </navigator>

      <!-- 解读 -->
      <navigator
        class="content_text"
        :url="`/pages/policy/policyDetails?id=${item.id}&inform=解读`"
        hover-class="className"
        v-show="contentTitleItem == 2"
        v-for="(item, j) in scrambleList"
        :key="j + item.id"
      >
        <view class="title">
          {{ item.title }}
        </view>
        <view class="name_data">
          <text class="departmentName">{{ item.departmentName }}</text>
          <text class="endTime">{{ item.declareTime }} 至 {{ item.deadline }}</text>
        </view>
      </navigator>

      <!-- 订阅政策 -->
      <view class="subscription_list" v-if="contentTitleItem == 4">
        <view class="subscription_item" v-for="(item, index) in getSubscript" :key="index" @tap="goSubscriptDelis(item.id)">
          <view class="subscription_item_title">
            {{ item.title }}
          </view>
          <view class="subscription_item_ctn">
            <text class="departmentName">{{ item.departmentName }}</text>

            <text class="endTime">{{ item.createTime.split(' ')[0] }}</text>
          </view>
        </view>
        <van-divider v-if="showText">我也是有底线的</van-divider>
      </view>
      <view class="no_subscript" v-show="controlSubscript && contentTitleItem == 1">
        <image :src="$imgUrl + 'static/no_subscription.png'" mode="" />
        <p>你还没有订阅的部门<navigator url="/pages/policy/policySubscription" class="className">点我去订阅</navigator></p>
      </view>
      <view class="no_subscript" v-show="contentTitleItem == 1 && isLogin">
        <image :src="$imgUrl + 'static/noLogin.png'" />
        <p>你还没有登录，<text @tap="goToLogin" class="goLogin">点我去登录</text></p>
      </view>
      <!-- 升级会员提示(查询企业数量已满) -->
      <van-overlay type="primary" v-show="visible" :close-on-click-overlay="false">
        <promptDialogBox :content="`/static/home/attention.png`" :msg="msg" :affirm="`升级会员`" @closeShow="handleClose" @controlShow="hanldClick" />
      </van-overlay>
    </view>
    <!-- <Festival></Festival> -->
  </view>
</template>

<script>
  import AMap from '../../util/map/Amap.js'
  var QQMapWX = require('@/static/qqmap-wx-jssdk/qqmap-wx-jssdk.js')
  import { companyList, policyList, projectList } from '../../util/api/es.js'
  import { getByIpGetLocation } from '../../util/api/index.js'
  import { debounce } from '../../util/debounce.js'
  import { getCode } from '../../util/address.js'
  import { newsList } from '../../util/api/newsList.js'
  import { deleteSearch, searchHistoryList } from '../../util/api/company.js'
  export default {
    data() {
      return {
        showText: false, // 显示没有数据的文字
        visible: false, // 是否显示登陆框
        currentIndex: 0, // 查企业关键字的索引
        titleItem: [], // 查企业内容
        titleContent: ['最新资讯', '政策通知', '政策解读'], // 导航栏的数据
        contentTitleItem: 0, // 切换导航栏的索引
        keyWord: '', // 输入的内容
        keyItem: [], //关键字列表
        companyNameItem: [], // 企业列表
        policy: [], // 政策列表
        projectList: [], // 查项目列表
        getInformation: [], // 获取资讯信息
        isLogin: false, // 是否有登录
        isSubsctiption: false, // 暂无没有订阅
        getSubscript: [], // 获取订阅列表
        msg: '', // 提示信息
        controlSubscript: false, // 控制是否有订阅列表
        isfixed: false, // 是否固定搜索框和标题
        resAmap: '', // 地图的结果集
        map: '', // 地图实例

        timeId: '',
        qqmapsdk: '',
        province: '',
        city: '定位中...',
        area: '',
        longitude: '',
        latitude: '',
        selectCity: false, // 能不能选择城市
        pageSize: 20,
        query: {},
        searchList: [],
        showHistory: false, //是否显示搜索历史

        sProvince: '',
        sCity: '',
        sCurrentLocation: '',
        total: 0,
        newsList: [],
        pageNo1: 1,
        newsTotal: 0,
        getNotifyList: [],
        pageNo2: 0,
        noticeTotal: 0,
        scrambleList: [],
        pageNo3: 1,
        scrambleTotal: 0,
      }
    },
    onShow() {
      let city = uni.getStorageSync('city')
      let currentLocation = uni.getStorageSync('currentLocation')
      if (city && currentLocation) {
        this.city = city
        this.getContentInfo(0)
        this.getContentInfo(1)
        this.getContentInfo(2)
      } else {
        this.getLocation()
      }
    },
    onLoad(query) {
      this.query = query
      // 获取标题
      this.getTitleItem()
      // 获取关键字
      this.getKeywrod('company')

      this.$store.dispatch('getCityNameError')
      this.sCity = uni.getStorageSync('city')
      this.sCurrentLocation = uni.getStorageSync('currentLocation')
      // 重新启动，如果有缓存去定位，不一样提示用户
      if (this.sCity && this.sCurrentLocation) {
        // this.city = city;
        this.getAdderss()
      }

      this.getSearchHistory()
    },
    watch: {
      currentIndex(val) {
        if (val) {
          this.keyWord = ''
          this.policy = []
          this.companyNameItem = []
          this.projectList = []
        }
      },
      keyWord: debounce(function (e) {
        this.keyWord = e.trim()
        if (e.trim() !== '') {
          this.showHistory = false
          this.changeValue()
        } else {
          this.showHistory = true
          this.companyNameItem = []
        }
      }, 1000),
    },
    // 页面滚动的高度
    onPageScroll(e) {
      if (Math.floor(e.scrollTop) >= 340) {
        this.isfixed = true
      } else {
        this.isfixed = false
      }
    },
    // 上拉加载更多
    onReachBottom() {
      // debugger
      // 加载下一页
      if (this.contentTitleItem == 0) {
        this.pageNo1 = this.pageNo1 + 1
        if (this.newsTotal > this.newsList.length) {
          this.getContentInfo(0)
        } else {
          this.showText = true
          uni.showToast({
            title: '没有更多内容啦',
            duration: 2000,
          })
        }
      } else if (this.contentTitleItem == 1) {
        this.pageNo2 = this.pageNo2 + 1
        if (this.noticeTotal > this.getNotifyList.length) {
          this.getContentInfo(1)
        } else {
          this.showText = true
        }
      } else if (this.contentTitleItem == 2) {
        this.pageNo3 = this.pageNo3 + 1
        if (this.scrambleTotal > this.scrambleList.length) {
          this.getContentInfo(2)
        } else {
          this.showText = true
        }
      }
    },

    methods: {
      // 历史搜索记录
      getSearchHistory() {
        searchHistoryList({ pageNo: 1, pageSize: 10 }).then(res => {
          if (res.code === 200) {
            this.searchList = res.result.records
          }
        })
      },
      toClear() {
        let _this = this
        uni.showModal({
          title: '提示',
          content: '确定清空历史记录',
          cancelText: '考虑一下',
          success(res) {
            if (res.confirm) {
              deleteSearch().then(res => {
                if (res.code === 200) {
                  uni.showToast({
                    title: '操作成功',
                    duration: 2000,
                    icon: 'none',
                  })
                  this.searchList = []
                  _this.getSearchHistory()
                }
              })
            }
          },
        })
      },
      toMore() {
        uni.navigateTo({
          url: '/pages/mime/searchHistory',
        })
      },
      getStorage() {
        //判断本地信息是否有值,如果有直接获取
        let city = uni.getStorageSync('city')
        let currentLocation = uni.getStorageSync('currentLocation') // 当前定位

        if (city && currentLocation) {
          this.city = city
          this.getContentInfo(0)
        } else {
          this.getLocation()
        }
      },
      // 从本地中获取定位
      getLocation() {
        this.$get('/bmj-api/api/sys/depart/getSubInfo', {}).then(res => {
          if (res.result.province !== '' && res.result.city !== '') {
            // if (res.result.province === '' && res.result.city === '') {
            // uni.setStorageSync("city", '东莞市'); // 城市名
            // uni.setStorageSync("province", '广东省'); // 省份名
            // uni.setStorageSync("currentLocation", '东莞市');
            uni.setStorageSync('province', res.result.province)
            uni.setStorageSync('city', res.result.city)
            uni.setStorageSync('currentLocation', res.result.city)
            this.selectCity = false
            this.city = uni.getStorageSync('city')
            this.getContentInfo(0)
          } else {
            this.selectCity = true
            let city = uni.getStorageSync('city')
            let currentLocation = uni.getStorageSync('currentLocation')
            // console.log(666666666,currentLocation)
            if (city && currentLocation) {
              this.city = city
              this.getContentInfo(0)
            } else {
              this.init()
            }
          }
        })
      },
      // 获取定位信息
      async init() {
        let data = await this.getProvince()
        // console.log(99999999,data)
        let _this = this
        if (!data) {
          uni.showModal({
            title: '提示',
            confirmText: '确认',
            cancelText: '取消',
            content: '您的地理位置获取失败，刷新重试！取消 将默认广州市。',
            success: function (res) {
              if (res.confirm) {
                _this.getProvince()
              } else {
                _this.province = '广东省' // 省
                _this.city = '广州市' // 市
                uni.setStorageSync('province', _this.province)
                uni.setStorageSync('city', _this.city)
                uni.setStorageSync('currentLocation', _this.city)
                _this.getContentInfo(0)
              }
            },
          })
        }
      },
      async getProvince() {
        let isAddress
        let res = await getByIpGetLocation()
        if (res.status === 0) {
          this.$nextTick(() => {
            this.province = res.province // 省
            this.city = res.city // 市
            uni.setStorageSync('province', this.province)
            uni.setStorageSync('city', this.city)
            uni.setStorageSync('currentLocation', this.city)
            this.getContentInfo(0)
          })
          isAddress = true
        } else {
          isAddress = false
        }
        return isAddress
      },
      getAdderss() {
        this.$get('/bmj-api/api/sys/depart/getSubInfo', {}).then(res => {
          if (res.result.province !== '' && res.result.city !== '') {
            this.selectCity = false
          } else {
            this.selectCity = true
            getByIpGetLocation().then(res => {
              let province = res.province
              let city = res.city
              let _this = this
              if (city !== this.sCity) {
                uni.showModal({
                  title: '提示',
                  confirmText: '确认',
                  cancelText: '考虑一下',
                  content: '您目前的位置和您所在地区不一致，是否切换',
                  success: function (res) {
                    if (res.confirm) {
                      _this.province = province // 省
                      _this.city = city // 市
                      uni.setStorageSync('province', _this.province)
                      uni.setStorageSync('city', _this.city)
                      uni.setStorageSync('currentLocation', _this.city)
                      _this.getContentInfo(0)
                    } else {
                      console.log('点击取消')
                    }
                  },
                })
              } else {
                this.getContentInfo(0)
              }
            })
          }
        })
      },
      // 选择城市
      selectLocation() {
        if (this.selectCity) {
          uni.navigateTo({
            url: '/pages/index/selectLocation',
          })
          this.getInformation = [] // 赋值都将清空
        } else {
        }
      },

      // 点击查政策列表内容
      gotoPolicy(id, val) {
        if (this.currentIndex == 1) {
          this.keyWord = ''
          this.policy = []
          this.$matcheHTML(val) // 去除html标签
          uni.navigateTo({
            url: '/pages/policy/policyDetails?id=' + id + '&inform=通知',
          })
        }
      },
      // 点击查项目列表内容
      gotoProject(val) {
        // console.log(val);
        val = this.$matcheHTML(val) // 去除html标签
        if (this.currentIndex == 2) {
          this.keyWord = ''
          this.projectList = []
          uni.navigateTo({
            url: `/pages/project/index?title=${val}`,
          })
        }
      },
      currentItem(index, val) {
        this.currentIndex = index
        this.keyWord = ''
        this.getKeywrod(val)
        this.showHistory = false
      },
      // 监听输入框的值
      changeValue() {
        this.showHistory = false
        if (this.currentIndex === 0 && this.keyWord !== '') {
          this.getCompanyList()
        } else if (this.currentIndex === 1 && this.keyWord !== '') {
          this.getPolicyList()
        } else if (this.currentIndex == 2 && this.keyWord !== '') {
          this.getProjectList()
        }
      },
      // input获取焦点时，显示企业搜索历史
      getHistoryList(index, type) {
        if (index == 0 && this.keyWord === '' && type === 'focus') {
          this.getSearchHistory()
          this.showHistory = true
        } else if (index == 0 && type === 'blur') {
          setTimeout(() => {
            this.showHistory = false
          }, 500)
        } else {
          this.showHistory = false
        }
      },
      // 点击查公司列表内容
      goToCompanyList(id, companyName) {
        if (this.currentIndex == 0) {
          this.keyWord = ''
          this.companyNameItem = []
          if (companyName) {
            let temp = companyName.replace(/<\/?.+?>/g, '')
            companyName = temp.replace(/ /g, '')
          }
          uni.navigateTo({
            url: `/pages/enterpriseDetails/brand_detail?id=${id}&type=1&name=${companyName}&liIndex=0&showNew=true`,
          })
        }
      },
      // 点击搜索按钮
      handleBtn() {
        if (this.currentIndex == 0) {
          // 查企业
          if (this.keyWord == '') {
            // 当企业为空时,做提示
            uni.showToast({
              title: '请输入企业名称',
              duration: 2000,
              icon: 'none',
            })
            return
          }
          uni.navigateTo({
            url: '/pages/enterpriseDetails/findCompany?type=company&enterprise=' + this.keyWord,
          })
        } else if (this.currentIndex == 1) {
          // 查政策
          if (this.keyWord == '') {
            // 当企业为空时,做提示
            uni.showToast({
              title: '请输入您想要查询的政策',
              duration: 2000,
              icon: 'none',
            })
            return
          }
          uni.navigateTo({
            url: '/pages/policy-check/index?title=' + this.keyWord,
            // url: `/pages/policy/index?title=${this.keyWord}`
          })
        } else if (this.currentIndex == 2) {
          if (this.keyWord == '') {
            // 当项目搜索框为空时,做提示
            uni.showToast({
              title: '请输入您想要查询的项目',
              duration: 2000,
              icon: 'none',
            })
            return
          }
          // console.log(345);
          uni.navigateTo({
            url: '/pages/project/index?title=' + this.keyWord,
          })
        }
      },
      // 点击查项目的列表项
      examProject(id, val) {
        uni.navigateTo({
          url: '/pages/project/index?title=' + val,
        })
      },
      // 获取标题(请求)
      getTitleItem() {
        this.$get('/bmj-api/api/home/getHomeDictConfigInfo').then(res => {
          if (res.code == 200) {
            this.titleItem = res.result
          }
        })
      },
      // 点击关键字(热门搜索)
      hanlderItem(id, val) {
        if (this.currentIndex == 0) {
          uni.navigateTo({
            url: `/pages/enterpriseDetails/brand_detail?id=${id}&type=1&liIndex=0&showNew=true`,
          })
        } else if (this.currentIndex == 1) {
          uni.navigateTo({
            url: '/pages/policy-check/index?title=' + val,
          })
        } else if (this.currentIndex == 2) {
          uni.navigateTo({
            url: '/pages/project/index?title=' + val,
          })
        }
      },
      // 获取信息(政策资讯)
      getContentInfo(index) {
        let city = uni.getStorageSync('city') || ''
        uni.showLoading({
          title: '加载中',
        })
        if (this.contentTitleItem == 0 && index == 0) {
          this.getNewsList()
        } else if (this.contentTitleItem == 1 && index == 1) {
          this.getNotice() // 获取订阅列表数据
        } else if (this.contentTitleItem == 2 && index == 2) {
          this.getinterpret() // 获取订阅列表数据
        }
      },
      // 最新资讯
      getNewsList() {
        let city = uni.getStorageSync('city')
        let province = uni.getStorageSync('province')
        let area = ''
        let params = {
          province: province, // 省份
          city: city, // 城市
          area: area, // 地区
          title: '',
          pageNo: this.pageNo1,
        }
        newsList(params)
          .then(res => {
            if (this.pageNo1 === 1) {
              this.newsList = res.result.records || []
            } else {
              this.newsList = this.newsList.concat(res.result.records)
            }
            this.newsTotal = res.result.total
          })
          .finally(() => {
            uni.hideLoading()
          })
      },
      // 政策通知
      getNotice() {
        let city = uni.getStorageSync('city')
        let province = uni.getStorageSync('province')
        let area = ''
        let params = {
          beginDate: '',
          dq: getCode(province, city, area),
          endDate: '',
          pageIndex: this.pageNo2,
          pageSize: 10,
          policyId: '',
          source: '',
          title: '',
          userID: '',
        }
        this.$post('/bmj-api/api/es/Policy/queryPolicyList.json', params)
          .then(res => {
            if (res.retCode === 0) {
              if (this.pageNo0 === 0) {
                this.getNotifyList = res.data.content || []
              } else {
                this.getNotifyList = this.getNotifyList.concat(res.data.content)
              }
              this.noticeTotal = res.data.totalElements
            }
          })
          .finally(() => {
            uni.hideLoading()
          })
      },
      // 政策解读
      getinterpret() {
        let city = uni.getStorageSync('city')
        let province = uni.getStorageSync('province')
        let obj = {
          pageNo: this.pageNo3,
          pageSize: 10,
          city: city,
        }
        this.$get('/bmj-api/api/pms/pmsPolicyInterpret/list', obj)
          .then(res => {
            if (res.code == 200) {
              if (this.pageNo3 === 1) {
                this.scrambleList = res.result.records || []
              } else {
                this.scrambleList = this.scrambleList.concat(res.result.records)
              }
              this.scrambleTotal = res.result.total
            }
          })
          .finally(() => {
            uni.hideLoading()
          })
      },
      // 控制弹出层显示或隐藏
      hanldClick() {
        this.visible = false
        // 跳转到会员页面
        uni.navigateTo({
          url: '/pages/VIP/index',
        })
      },
      handleClose() {
        this.visible = false
      },
      // 获取关键字
      getKeywrod(val) {
        this.$get('/bmj-api/api/home/getSearchKeywordsInfo', { type: val }).then(res => {
          this.keyItem = res.result
        })
      },
      // 切换最新资讯和政策通知列表
      hanlderEvent(index) {
        this.newsList = []
        this.pageNo1 = 1
        this.pageNo2 = 0
        this.pageNo3 = 1
        this.scrambleList = []
        this.getNotifyList = []

        this.contentTitleItem = index
        this.getContentInfo(index) // 传递索引
      },
      // 点击订阅列表详情
      goSubscriptDelis(id) {
        // 跳转到政策通知
        uni.navigateTo({
          url: '/pages/policy/policyDetails?id=' + id + '&inform=通知',
        })
      },
      // 输入框企业查询
      getCompanyList() {
        let obj = {
          companyName: this.keyWord,
          pageIndex: 0,
          pageSize: 10,
          province: '',
        }
        companyList(obj).then(res => {
          if (res.retCode == 0 && res.data.content.length) {
            let result = this.$changeText(res.data.content, 'companyName', this.keyWord)
            this.companyNameItem = result
          }
        })
      },
      // 输入框政策查询
      getPolicyList() {
        let city = uni.getStorageSync('city')
        let province = uni.getStorageSync('province')
        let area = ''
        let obj = {
          pageIndex: 0,
          pageSize: 10,
          dq: getCode(province, city, area),
          source: '',
          title: this.keyWord,
        }
        policyList(obj).then(res => {
          if (res.retCode == 0 && res.data.content.length) {
            let result = this.$changeText(res.data.content, 'title', this.keyWord)
            this.policy = result
          }
        })
      },
      // 输入框项目查询
      getProjectList() {
        let city = uni.getStorageSync('city')
        let province = uni.getStorageSync('province')
        let area = ''
        let obj = {
          province: province,
          city: city,
          area: area,
          projectName: this.keyWord,
          pageIndex: 0,
          pageSize: 1000,
        }
        projectList(obj).then(res => {
          if (res.retCode == 0 && res.data.content.length != 0) {
            let result = this.$changeText(res.data.content, 'projectName', this.keyWord)
            this.projectList = []
            var temp = []
            for (let i = 0; i < result.length; i++) {
              if (temp.indexOf(result[i].projectName) == -1) {
                temp.push(result[i].projectName)
                this.projectList.push(result[i])
              }
            }
          } else {
            uni.showToast({
              title: res.message,
              duration: 2000,
              icon: 'none',
            })
            this.projectList = []
          }
        })
      },

      // 点击登录
      goToLogin() {
        uni.setStorageSync('pageUrl', window.location.href)
        uni.navigateTo({
          url: '/pages/login/index',
        })
      },
      toPage(login, url) {
        if (login) {
          let token = this.$getToken()
          if (!token) {
            uni.showToast({
              title: '请登录后,再操作',
              duration: 2000,
              iocn: 'none',
            })
            uni.setStorageSync('pageUrl', window.location.href)
            uni.navigateTo({
              url: '/pages/login/index',
            })
          } else {
            uni.navigateTo({
              url: url,
            })
          }
        } else {
          uni.navigateTo({
            url: url,
          })
        }
      },
    },
  }
</script>

<style lang="less" scoped>
  .container {
    position: relative;
    z-index: 1;
    .declare-search {
      position: fixed;
      left: 20rpx;
      bottom: 180rpx;
      width: 76rpx;
      height: 76rpx;
      border-radius: 50%;
      font-size: 24rpx;
      text-align: center;
      line-height: 76rpx;
      background: rgba(0, 0, 0, 0.7);
      color: #eee;
    }
    .top_bar {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-around;
      // padding-bottom: 30px;
      background-image: url(https://dm-bmj.oss-cn-guangzhou.aliyuncs.com/static/index-bg.png);
      background-size: cover;
      height: 480rpx;
      .logo {
        max-width: 320rpx;
        height: 80rpx;
        image {
          max-width: 320rpx;
          height: 80rpx;
        }
      }
      .search_bar {
        width: 100%;
        position: relative;
        padding: 0 56rpx 0;
        .location {
          display: flex;
          align-items: center;
          position: absolute;
          padding: 10rpx 30rpx;
          // border: 1rpx solid #ccc;
          font-size: 14px;
          left: 30rpx;
          top: -160rpx;
          color: #fff;
          svg {
            width: 40rpx;
            height: 30rpx;
            margin-left: 10rpx;
          }
        }
        .search_bar_top {
          text {
            padding: 10rpx 20rpx;
            font-size: 14px;
            margin-right: 25rpx;
            color: #fff;
            border-radius: 48rpx;
            &.active {
              font-weight: 700;
              background-color: #44a2ff;
            }
          }
        }
        .search_barimage {
          display: flex;
          position: relative;
          align-items: center;
          justify-content: space-around;
          background-color: #fff;
          border-radius: 6rpx;
          margin: 32rpx 0rpx;
          padding: 10rpx;
          width: 100%;
          input {
            color: #000;
            width: 500rpx;
            height: 60rpx;
            font-size: 12px;
            background-color: #fff;
            &:placeholder {
              color: #ccc;
            }
          }
          image {
            width: 35rpx;
            height: 35rpx;
          }
          .dataBox {
            z-index: 999;
            position: absolute;
            width: 620rpx;
            background-color: #fff;
            top: 80rpx;
            overflow-y: auto;
            .list-content {
              display: flex;
              // flex-wrap: wrap;
              flex-direction: column;
              overflow-y: auto;
              // padding: 0 20rpx;
              max-height: 500rpx;
              .policy_item {
                padding: 0 20upx;
                box-sizing: border-box;
              }
              .search-history {
                view {
                  font-size: 12px;
                  padding: 5upx 10upx;
                  background: #eee;
                  margin-bottom: 5px;
                }
              }
              .search-history-btn {
                background: #eee;
                padding: 20upx 10upx;
                box-sizing: border-box;
                view {
                  margin-right: 20upx;
                  font-size: 24upx;
                  color: #999;
                }
              }
              .policy_item {
                display: flex;
                align-items: center;
                font-size: 12px;
                height: 70rpx;
                border-bottom: 1rpx solid #e4e4e4;
                overflow: hidden;
                white-space: nowrap;
                &:hover {
                  color: #44a2ff;
                }
              }
            }
          }
        }
        .search_bar_keyword {
          min-height: 40px;
          display: flex;
          align-items: center;
          color: #fff;
          .title {
            width: 150rpx;
            font-size: 14px;
          }
          .keyWord {
            // display: flex;
            // flex: 1;
            // flex-wrap: wrap;

            span {
              margin: 0 10rpx;
              font-size: 14px;
              color: #9fc2f1;
            }
          }
          p {
          }
        }
      }
    }
    /* 固定样式 */
    .fixation_box {
      width: 100%;
      z-index: 100;
      // display: none;
      position: fixed;
      top: 0;
      left: 0;
      border-bottom: 1rpx solid #ccc;
      .fixation_search {
        height: 120rpx;
        background-color: #2862ad;
        padding: 20rpx 40rpx;
        .search_bar {
          display: flex;
          align-items: center;
          background-color: #fff;
          padding: 0 20rpx;
          height: 100%;
          border-radius: 10rpx;
          input {
            width: 100%;
            height: 100%;
          }
          image {
            width: 32rpx;
            height: 32rpx;
          }
        }
      }
      .fixation_title {
        height: 100rpx;
        display: flex;
        align-items: center;
        padding: 0 30px;
        background-color: #fff;
        .title_item {
          position: relative;
          width: 40%;
          font-size: 14px;
          color: #aaa;
          text-align: center;
          &.active {
            color: #333;
            font-weight: 700;
            font-size: 18px;
            &::before {
              content: '';
              position: absolute;
              left: 40%;
              bottom: -30rpx;
              width: 30rpx;
              height: 5px;
              border-radius: 4rpx;
              background-color: #1678ff;
            }
          }
        }
      }
      .sreach_content {
        min-width: 620rpx;
        position: relative;
        // margin:0 auto;
        ul {
          min-width: 660rpx;
          position: absolute;
          top: 30rpx;
          left: 50%;
          right: 50%;
          transform: translate(-50%, -50%);
          background-color: #fff;
          max-height: 300rpx;
          overflow-y: auto;
          .list {
            white-space: nowrap;
            height: 60rpx;
            line-height: 60rpx;
            padding-left: 10rpx;
            border-bottom: 1rpx solid #ccc;
            p {
            }
          }
        }
      }
    }
    .icon-list {
      padding: 0 30rpx;
      margin-bottom: 20rpx;
      background-color: #fff;
      .item {
        width: 180rpx;
        margin: 20rpx;
        .dot {
          width: 100rpx;
          height: 100rpx;
          border-radius: 50%;
          background: rgb(93, 228, 217);
          img {
            width: 50rpx;
            height: 50rpx;
          }
        }

        .text {
          margin-top: 15rpx;
        }
      }
      .item:first-child .dot {
        background-image: linear-gradient(to right, #1678ff, #6d6bed);
      }
      .item:nth-child(2) .dot {
        background-image: linear-gradient(to right, #d567e4, #ff68b0);
      }
      .item:nth-child(3) .dot {
        background-image: linear-gradient(to right, #6dfacd, #00daf2);
      }
      .item:nth-child(4) .dot {
        background-image: linear-gradient(to right, #ff907c, #ffc65d);
      }
      .item:nth-child(5) .dot {
        background-image: linear-gradient(to right, #B89FE7, #816CAF);
      }
      .item:nth-child(6) .dot {
        background-image: linear-gradient(to right, #66B1F3, #1D7DBB);
      }
      .item:nth-child(7) .dot {
        background-image: linear-gradient(to right, #F9F871, #FFD05E);
      }
      .item:nth-child(8) .dot {
        background-image: linear-gradient(to right, #f12759, #b1002c);
      }
      .item:last-child .dot {
        background-image: linear-gradient(to right, #6d6bed, #915dd8);
      }
    }
    .content {
      background-color: #fff;
      padding-bottom: 100rpx;
      .title_text {
        height: 120rpx;
        display: flex;
        border-bottom: 1rpx solid #ebebeb;
        span {
          width: 40%;
          height: 100%;
          display: flex;
          font-size: 14px;
          align-items: center;
          justify-content: center;
          &.active {
            position: relative;
            font-weight: 700;
            font-size: 18px;
            &::before {
              content: '';
              position: absolute;
              left: 40%;
              bottom: 0px;
              width: 40rpx;
              height: 5px;
              border-radius: 20rpx;
              background-color: #4e98ff;
            }
          }
        }
      }
    }
    .content_text {
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      padding: 20rpx 30rpx;
      border-bottom: 1rpx solid #ebebeb;
      .title {
        font-size: 16px;
        font-weight: 700;
        margin-bottom: 20rpx;
      }
      .name_data {
        font-size: 12px;
        color: #c7c7c7;
        display: flex;
        justify-content: space-between;
        .departmentName {
          // max-width: 50%;
          // white-space: nowrap;
          // overflow: hidden;
          // text-overflow: ellipsis;
          padding-right: 20rpx;
          flex: 1;
        }
        .endTime {
          flex: 1;
          text-align: right;
        }
        // span {
        //   margin-right: 40rpx;
        //   &:last-child {
        //     margin-left: 40rpx;
        //     margin-right: 0rpx;
        //   }
        // }
      }
    }
    .no_subscript {
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      padding: 118rpx 0;
      image {
        width: 320rpx;
        height: 172rpx;
      }
      .goLogin {
        color: #1678ff;
      }
      p {
        display: flex;
        font-size: 14px;
        margin-top: 40rpx;
        color: #3c4d5b;
        .className {
          color: #44a2ff;
          // font-size: 28rpx;
        }
      }
    }
    .subscription_list {
      padding: 0 30rpx;
      padding-bottom: 55rpx;
      .subscription_item {
        display: flex;
        flex-direction: column;
        padding: 40rpx 15rpx;
        border-bottom: 1rpx solid #ccc;
        .subscription_item_title {
          font-size: 16px;
          color: #333;
          font-weight: 700;
        }
        .subscription_item_ctn {
          display: flex;
          align-items: center;
          justify-content: space-between;
          color: #aaaaaa;
          font-size: 13px;
          margin-top: 20rpx;
          .departmentName {
            max-width: 50%;
            /* 显示省略号 */
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }
          .endTime {
          }
        }
      }
    }
  }
  .van-popup {
    background: rgba(255, 255, 255, 0);
  }
</style>
